/***************************************************************
 * Name:      wxTsina_GUIMain.h
 * Purpose:   Defines Application Frame
 * Author:    Gui Qing (guiqing0402@163.com)
 * Created:   2010-11-13
 * Copyright: Gui Qing (http://t.sina.com.cn/guiqing0402)
 * License:
 **************************************************************/

#ifndef WXTSINA_GUIMAIN_H
#define WXTSINA_GUIMAIN_H
#include <wx/gauge.h>

//(*Headers(wxTsina_GUIFrame)
#include <wx/notebook.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/menu.h>
#include <wx/textctrl.h>
#include <wx/radiobut.h>
#include <wx/panel.h>
#include <wx/bmpbuttn.h>
#include <wx/button.h>
#include <wx/frame.h>
#include <wx/statusbr.h>
//*)

#include <vector>
#include <map>
#include <wx/imaglist.h>
#include <wx/statbox.h>
#include <wx/thread.h>
#include "GlobalConfig.h"

typedef std::vector< std::map<wxString, wxString> > tableType;
class CFollowersQueryInc;
class CLogin;
class BackendWorker_Login;
class BackendWorker_CFsync;
class BackendWorker_GetPIN;


class wxTsina_GUIFrame: public wxFrame
{
    public:
        wxTsina_GUIFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~wxTsina_GUIFrame();

        CFollowersQueryInc* GetData(){return CF;}
        wxCriticalSection*      pCF_CS;
        wxCriticalSection*      mpLogin_CS;
    private:

        //(*Handlers(wxTsina_GUIFrame)
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnButton_get_verifier(wxCommandEvent& event);
        void OnButton_submit_verifier(wxCommandEvent& event);
        void OnButton_start_syncClick(wxCommandEvent& event);
        void OnButton_clear_recordClick(wxCommandEvent& event);
        void OnButton_clear_recyclerClick(wxCommandEvent& event);
        //*)
        /**************   My Functions  ********************/
        void build_unfollowed_UI(tableType& unfollowed_info);
        void OnButton_unfoClick(wxCommandEvent& event);
        void OnButton_remvClick(wxCommandEvent& event);
        void OnButton_avatarClick(wxCommandEvent& event);
        void OnButton_review_selectClick(wxCommandEvent& event);
        void OnButton_login_resetClick(wxCommandEvent& event);
        void OnAtMe(wxCommandEvent& event);
        int matchIDs(long ID , std::vector<long> IDvec);

        /***************MT Event Handler*******************/
        void OnUpdateSubGauge(wxThreadEvent& event);
        void OnSubGaugePulse(wxThreadEvent& event);
        void OnUpdateTotalGauge(wxThreadEvent& event);
        void OnTotalGaugePulse(wxThreadEvent& event);
        void OnGetPinDone(wxThreadEvent& event);
        void OnLoginDone(wxThreadEvent& event);
        void OnCFsyncDone(wxThreadEvent& event);

        /***************Unit Test***********************/

#ifdef UNIT_TEST
        void Test_URLencode(wxCommandEvent& event);
        void Test_Oauth_Timestamp(wxCommandEvent& event);
        void Test_Oauth_Nonce(wxCommandEvent& event);
        void Test_Oauth_Sort(wxCommandEvent& event);
        void Test_Oauth_BaseString(wxCommandEvent& event);
        void Test_Oauth_Sha1(wxCommandEvent& event);
        void Test_Oauth_ReqTokenHeader(wxCommandEvent& event);
        void Test_Oauth_ReqTokenTest(wxCommandEvent& event);
        void Test_Oauth_AccessTokenTest(wxCommandEvent& event);
        void Test_HttpParamsExtraction(wxCommandEvent& event);
        void Test_XML_sampler(wxCommandEvent& event);
        void Test_XML_validator(wxCommandEvent& event);
        void Test_XML_refFind(wxCommandEvent& event);
        void Test_XML_errorCorrection(wxCommandEvent& event);
#endif

        /**********************************************/

        //(*Identifiers(wxTsina_GUIFrame)
        static const long ID_STATICTEXT1;
        static const long ID_TEXTCTRL1;
        //static const long ID_STATICTEXT2;
        static const long ID_TEXTCTRL2;
        static const long ID_BUTTON1;
        static const long ID_BUTTON_GET_VERIFIER;
        static const long ID_BUTTON2;
        static const long ID_BUTTON3;
        static const long ID_BUTTON4;
        static const long ID_BUTTON5;
        static const long ID_BUTTON6;
        static const long ID_BUTTON7;
        static const long ID_BUTTON8;
        static const long ID_STATICTEXT3;
        static const long ID_GAUGE1;
        static const long ID_STATICTEXT4;
        static const long ID_STATICTEXT5;
        static const long ID_GAUGE2;
        static const long ID_STATICTEXT6;
        static const long ID_PANEL1;
        static const long ID_RADIOBUTTON1;
        static const long ID_RADIOBUTTON2;
        static const long ID_BUTTON9;
        static const long ID_BITMAPBUTTON1;
        static const long ID_STATICTEXT7;
        static const long ID_BUTTON10;
        static const long ID_BUTTON11;
        static const long ID_TEXTCTRL3;
        //static const long ID_PANEL3;
        static const long ID_NOTEBOOK2;
        static const long ID_PANEL2;
        static const long ID_NOTEBOOK1;
        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        //*)

        //(*Declarations(wxTsina_GUIFrame)
        wxButton* Button_login_OK;
        wxButton* Button_getVerifier;
        wxButton* Button4;
        wxNotebook* Notebook1;


        //wxStaticText* StaticText2;
        wxPanel* Panel1;
        wxButton* Button_clear_record;
        wxStaticText* StaticText1;
        wxStaticText* StaticText3;
        wxButton* Button_remove_one;
        wxRadioButton* RadioButton_latest;
        wxButton* Button_start_sync;
        wxButton* Button_unfollow;
        wxPanel* Panel3;
        wxRadioButton* RadioButton_recycler;
        wxButton* ComingSoon;
        wxStatusBar* StatusBar1;
        wxButton* Button_review_select;

        wxTextCtrl* TextCtrl_verifier;
        wxButton* Button_clear_recycler;
        wxTextCtrl* unfollowed_info;
        wxPanel* Panel2;
        //wxTextCtrl* TextCtrl_password;
        wxBitmapButton* BitmapButton_avatar;

        wxNotebook* Notebook2;
        wxButton* Button8;
        wxButton* Button_login_reset;
        //*)

    /*****************UI for gauge/others*************************/
        wxStaticText* Total_progress_percent;
        wxStaticText* Total_progress_text;
        wxStaticText* Sub_progress_text;
        wxGauge* Gauge_sub;
        wxStaticText* Sub_progress_percent;
        wxGauge* Gauge_total;

        static const long ID_AT_ME;
        CFollowersQueryInc* CF;
        CLogin* mpLogin;

    /*************For Dynamicly Build UI***********************/

        std::vector<wxPanel*> v_panel;
        std::vector<wxFlexGridSizer*> v_flexGS_2col;
        std::vector<wxFlexGridSizer*> v_flexGS_left;
        std::vector<wxFlexGridSizer*> v_flexGS_right;
        std::vector<wxBitmapButton*> v_bmpButton_avatar;
        std::vector<bool> v_bmpButton_hasAvatar;
        std::vector<long> v_bmpButton_avatar_ID;
        std::vector<long> v_button_unfo_ID;
        std::vector<long> v_button_remv_ID;
        std::vector<wxStaticText*> v_isFollow;
        std::vector<wxButton*> v_button_unfo;
        std::vector<wxButton*> v_button_remv;
        std::vector<wxTextCtrl*> v_unfollowed_info;

        wxImageList imgList;

        wxStaticBox* sbox1;
        wxStaticBox* sbox2;
        wxStaticBox* sbox3;

        wxString mUserID;
        wxFont YaHeiFont9;
        wxFont YaHeiFont10;

        tableType unfollowed_from_recycler;
        tableType unfollowed_latest;
        bool mIsDisplayRecycler;
        bool mIsLogin;
        /***************MT Worker****************/
        BackendWorker_Login* pLoginMT;
        BackendWorker_CFsync* pCFsyncMT;
        BackendWorker_GetPIN* pGetPinMT;

    /************************************************/
        DECLARE_EVENT_TABLE()
};

#endif // WXTSINA_GUIMAIN_H
